#!/bin/bash
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-

core_pattern_file='/proc/sys/kernel/core_pattern'
core_pipe_limit_file='/proc/sys/kernel/core_pipe_limit'

default_core_pattern='|/bin/false'      # from linux kernel source
default_core_pipe_limit='0'             # from linux kernel source

core_pattern='|/usr/libexec/fpemud-os-sysman/coredump-handler.py %P %u %g %s %t %h %e'
core_pipe_limit='2147483647'            # 0x7fffffff

if [[ "$1" == "--check" ]]; then
    current_core_pattern=`cat $core_pattern_file`
    if [[ "$current_core_pattern" != "$core_pattern" ]]; then
        echo "Invalid content in $core_pattern_file"
    fi
    current_core_pipe_limit=`cat $core_pipe_limit_file`
    if [[ "$current_core_pipe_limit" != "$core_pipe_limit" ]]; then
        echo "Invalid content in $core_pipe_limit_file"
    fi
elif [[ "$1" == "--unregister" ]]; then
    echo "$default_core_pattern" > $core_pattern_file
    echo "$default_core_pipe_limit" > $core_pipe_limit_file
else
    echo "$core_pattern" > $core_pattern_file
    echo "$core_pipe_limit" > $core_pipe_limit_file
fi
